﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using GriffinWebService.Entity;
using GriffinWebService.DALC;

namespace GriffinWebService.BO
{
    public class userBO
    {
        #region [Member Variables]
        userDALC userDALC = new userDALC();
        #endregion

        #region [Register]
        public User register(User user, out string errormsg)
        {
            errormsg = string.Empty;
            //check username password email
            //...if need...

            //register
            try
            {
                if (user != null 
                    && !string.IsNullOrEmpty(user.Username)
                    && !string.IsNullOrEmpty(user.Password))
                {
                    user = userDALC.createUser(user);
                }
            }
            catch (Exception ex)
            {
                errormsg = ex.ToString();
            }

            return user;
        }
        #endregion 

        #region [Register]
        public int login(string username, string password, out string errormsg)
        {
            //login
            errormsg = string.Empty;
            User entity = null;

            try
            {
                entity = (User)userDALC.FindByUserNameAndPassword(username,password);
            }
            catch (Exception ex)
            {
                errormsg = ex.ToString();
            }

            if (entity != null)
            {
                return entity.UserID;
            }
            else
            {
                return 0;
            }
        }
        #endregion 
    }
}
